package com.jhh.pay.center.model;

import lombok.Getter;
import lombok.Setter;
import org.bouncycastle.util.Strings;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;

/**
 * @author tangxd
 * @Description: TODO
 * @date 2017/12/4
 */
@Getter
@Setter
public class PayChannel extends PropertyEntity implements Serializable {
    private final static String ALLOW_IP = "allow_ips";

    private int id;
    private String name;
    private String serviceName;
    private boolean enabled;
    private String key;
    private String version;
    private Date postTime = new Date();

    /**
     * 设置支付组件ip白名单
     *
     * @param ips
     */
    public void setAllowIPs(String[] ips) {
        if (null == ips) {
            this.setProperty(ALLOW_IP, "");
            return;
        }
        this.setProperty(ALLOW_IP, String.join(",", ips));
    }

    public String[] getAllowIPs() {
        Object ips = this.getProperty(ALLOW_IP);
        if (ips == null) {
            return new String[0];
        }
        return Strings.split(ips.toString(), ',');
    }
}
